<?php

final class Util_ArrayMapper
{
    private $_keyName = null;
    private $_valueName = null;

    public function  __construct($keyName, $valueName)
    {
        $this->_keyName = $keyName;
        $this->_valueName = $valueName;
    }

    public function toMap(array $array)
    {
        return array_reduce($array, array($this, '_toMapCallback'));
    }

    private function _toMapCallback($map, $element)
    {
        if (is_array($element) && isset($element[$this->_keyName])
            && isset($element[$this->_valueName])) {

            $map[$element[$this->_keyName]] = $element[$this->_valueName];
        }

        return $map;
    }
}

